<?php
namespace app\admin\controller;

use think\Db;
use think\facade\Cache;

class Site extends Base
{
	public function site()
	{
        $site = Db::table('site')->find(1);
        $this->assign('site', $site ? $site : []);

		return $this->fetch();
	}

    public function siteSave()
    {
        if ($this->request->isPost() && $this->request->isAjax()) {
            $data = $this->request->param();
            unset($data['file']);
            if (!Db::table('site')->update($data)) {
                $this->result('', 1, '保存失败');
            }

            // 更新网站设置缓存
            Cache::set('site', Db::table('site')->find(1) ?: []);

            $this->result('', 0, '保存成功');
        }
    }
}
